<template>
  <div class="home">
    <el-container>
      <el-header style="position: relative;">学生选课系统
        <p style="color: white;">用户名：{{ $store.state.xixi.userInfo.username }}</p>
        <el-button class="aa" type="primary" @click="logout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu :default-active="$route.path" class="el-menu-vertical-demo" background-color="#324157"
            text-color="#fff" active-text-color="#20A0FF" router>
            <el-menu-item :index="item.path" v-for="item in routes" :key="item.path">
              <i :class="item.meta?.icon"></i>
              <span slot="title">{{ item.meta ? item.meta.title : item.path }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <i class="el-icon-edit"></i>
          <el-card class="box-card">
            <router-view>
            </router-view>
          </el-card>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  data() {
    return {
      routes: []
    }
  },
  methods: {
    logout() {
      this.$store.commit('xixi/changeUserInfo',{})
          this.$router.push('/login')
          
          
    }
  },
  mounted() {
    console.log(this.$route);
    console.log(this.$router);
    
    if (this.$store.state.xixi.userInfo.userType == 3) {
      this.routes = this.$router.options.routes.find(item => item.path == "/home").children
    } else {
      this.routes = this.$router.options.routes.find(item => item.path == "/teacher").children
    }

    this.routes = this.routes.filter(item => {
      return this.$store.state.xixi.userInfo.permissions.indexOf(item.meta.id) != -1 || !item.meta.id
    })
    // this.routes = this.$router.options.routes[2].children
    // this.routes = this.routes.filter(item => {
    //   return this.$store.state.xixi.userInfo.permissions.indexOf(item.meta.id) != -1 || !item.meta.id
    // })
  }
}
</script>
<style lang="scss" scoped>
.aa{
  position: absolute ;right: 20px;
}
.home {
  height: 100%;

  .el-container {
    height: 100%;

    .el-container {
      height: calc(100% - 60px);
    }
  }

  .el-header {
    background-color: #242F42;
  }

  .el-aside {
    background-color: #324157;
  }

  .el-main {
    background-color: #F0F0F0;
    padding: 10px;
  }

  .el-card {
    min-height: 100%;
  }

}
</style>
